<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>内容分发系统管理端</title>
		<link rel="icon" href="favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="${request.contextPath}/static/lib/layui/css/layui.css">
		<link rel="stylesheet" href="${request.contextPath}/static/css/style.css">
		<script src="${request.contextPath}/static/lib/jquery-3.1.1.js"></script>
		<script src="${request.contextPath}/static/lib/layui/layui.js"></script>
		<script src="${request.contextPath}/static/lib/layui/lay/dest/layui.all.js"></script>
		<style type="text/css">
			.layui-layedit{
				height: 500px;
			}
		</style>
	</head>
	<body style="height:800px;">
		<div class="layui-tab-item layui-show" style="margin-top: 15px;">
			<div id="queryDiv" class="layui-form" style="width: 400px;">
				<div style="display: none">
					<label class="control-label">ID</label>
				    <input id="id" type="text" class="form-control" <#if bean??> value="${bean.id}" </#if>>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">标题</label>
					<div class="layui-input-block">
						<input id="title" type="text" required placeholder="" class="layui-input" <#if bean??> value="${bean.title}" </#if>>
					</div>
					<div class="layui-input-text"><i class="font-red">*</i></div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">内容</label>
					<div class="layui-input-block layui-ckeditor">
						<div id="editor"><#if bean??> ${bean.context} </#if></div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-normal" onclick="save()">保存</button>
						<button class="layui-btn layui-btn-warm" onclick="reload()">重置</button>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript" charset="utf-8" src="${request.contextPath}/static/lib/ckeditor/ckeditor.js"></script>
		<script type="text/javascript" charset="utf-8" src="${request.contextPath}/static/lib/ckeditor/config.js"></script>
		<script type="text/javascript">
			var hot = "<#if bean??>${bean.hot}</#if>";
			layui.use(['form', 'laydate'], function(){
				var form = layui.form();
				form.on('radio', function(data){
					hot = data.value;
				});
			});
			
			CKEDITOR.replace('editor', {
				height: 270,
				extraPlugins: 'image',
				filebrowserUploadUrl: '/image/upload?path=notice',
			});
			
			function save(){
				var id = $("#id").val();
				var title = $("#title").val();
				var context = CKEDITOR.instances.editor.getData();
				if(title.length > 255){
					layer.msg('标题不能超过255个字符', {icon : 0});
					return false;
				}
				var data = {"id" : id, "title" : title, "context" : context};
				 $.post("update.json", data, function(res){
					if(res.code == 0){
						layer.msg("提交成功!", {icon : 1});
						parent.reloadBean("${index}", data);
					}else{
						layer.msg(res.message.info, {icon : 2});
					}
				});
			}
			function reload(){
				location.reload(true);
			}
		</script>
	</body>
</html>
